import { DirValueType } from "@/types/typesInForm/DirValueType";
import { GitValueType } from "@/types/typesInForm/GitValueType";
import { ResData } from "@/types/typesInForm/ResData";
import VisFragment from "@/types/VisFragment";
import { message } from "antd";
import axios from "axios";

export async function formCommit(
  data: (GitValueType & { ifLocal: boolean }) | DirValueType,
  url: string
): Promise<VisFragment | null> {
  try {
    const res: ResData<VisFragment> = (
      await axios.get(url, {
        params: data,
      })
    ).data;
    if (res.ifSuccessful) {
      return res.data;
    } else {
      message.error(res.message);
      return null;
    }
  } catch (e) {
    console.error(e);
    message.error("错误，无响应！");
    return null;
  }
}
